﻿// Author: Iulian Lita
// Project: UIModule
// Path: C:\Users\Tym\Documents\Visual Studio 2008\Projects\Library\UIModule
// Creation date: 1/13/2009 11:05 PM
// Last modified: 1/14/2009 4:40 AM

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UsersModule.UserActions;


namespace UIModule
{
    public partial class PublisherForm : Form
    {
        Form _parentForm;
        PublisherActions _userActions;

        #region Properties
        /// <summary>
        /// Parent form
        /// </summary>
        public Form ParentForm
        {
            get { return _parentForm; }
            set { _parentForm = value; }
        } // ParentForm
        #endregion

        public PublisherForm(PublisherActions userActions)
        {
            _userActions = userActions;
            InitializeComponent();
        }

        private void exit_btn_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void addItmesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddItems addItemsForm = new AddItems();
            addItemsForm.Show();

        }

        private void logout_btn_Click(object sender, EventArgs e)
        {
            _parentForm.Show();
            this.Dispose();
        }

        private void PublisherForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'allFieldsLibrary.domeniu' table. You can move, or remove it, as needed.
            this.domeniuTableAdapter.Fill(this.allFieldsLibrary.domeniu);
            // TODO: This line of code loads data into the 'allFieldsLibrary.tipProdus' table. You can move, or remove it, as needed.
            this.tipProdusTableAdapter.Fill(this.allFieldsLibrary.tipProdus);
            // TODO: This line of code loads data into the 'libraryDataSet.utilizator' table. You can move, or remove it, as needed.
            this.utilizatorTableAdapter.Fill(this.libraryDataSet.utilizator);
            // TODO: This line of code loads data into the 'allFieldsLibrary.detaliiProdus' table. You can move, or remove it, as needed.
            this.detaliiProdusTableAdapter.Fill(this.allFieldsLibrary.detaliiProdus);

        }

        private void recommend_btn_Click(object sender, EventArgs e)
        {
            _userActions.makeRequest(title_tbox.Text, author_tbox.Text, textBoxAnAparitie.Text, (int)comboBoxTipDomeniu.SelectedValue, (int)comboBoxTipProdus.SelectedValue, textBoxDescriere.Text);
            this.detaliiProdusTableAdapter.Fill(this.allFieldsLibrary.detaliiProdus);

        }

        private void publisher_tctrl_TabIndexChanged(object sender, EventArgs e)
        {
            this.detaliiProdusTableAdapter.Fill(this.allFieldsLibrary.detaliiProdus);
        }

     

        private void go_btn_Click(object sender, EventArgs e)
        {
            try
            {
                if (pSearchBy_cbox.SelectedIndex == 0)
                    detaliiProdusTableAdapter.SelectByTitle(allFieldsLibrary.detaliiProdus, pSearch_tbox.Text);
                else
                    detaliiProdusTableAdapter.SelectByAuthor(allFieldsLibrary.detaliiProdus, pSearch_tbox.Text);
            }
            catch (Exception exc)
            {
                MessageBox.Show("Unable to search in database!!");
                Error.ErrorManagement.ManageException(exc);
            }
        }

        private void addNo_btn_Click(object sender, EventArgs e)
        {
            try
            {
                int noItems = int.Parse(addNo_tbox.Text);

                for (int i = 0; i < noItems; i++)
                {
                    _userActions.addItem(int.Parse(textBoxPrice.Text), (int)dgwProducts.SelectedRows[0].Cells[0].Value);
                }
            }
            catch (Exception exc)
            {
                
                Error.ErrorManagement.ManageException(exc);

            }

 
        }

       
    }
}
